﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CdcSoftware.Pivotal.Applications.Core.Client;
using CdcSoftware.Pivotal.Engine.UI.Forms;
using CdcSoftware.Pivotal.Applications.Core.Common;
using CdcSoftware.Pivotal.Engine.Client.Services.Interfaces;
using System.Data;
using CdcSoftware.Pivotal.Engine;

namespace Pcm.Retail.Client.FormTasks
{
    public partial class RE_Line_Of_Business : FormClientTask
    {        
        /// <summary>
        /// Event gets triggered with the click of Test Apple Care Button.
        /// </summary>
        /// <param name="sender">The control associated with the event triggered</param>
        /// <param name="args">The argument for the event</param>
        /// <history>
        /// #Revision   Date            Author      Description
        /// 6.0.12.0    2013-09-13      AS          Initial version for Retail.
        /// </history>
        public virtual void OnButtonClickCheckAppleCare(PivotalControl sender, EventArgs args)
        {
            try
            {
                if (this.FormView.Dirty)
                {
                    if (!this.SaveRecord())
                    {
                        return;
                    }
                    this.LoadRecord();
                }
                string message = "Apple Care Authentication is successful.";

                Globals.AppleCareSessionDateTime = DateTime.MinValue;                

                Globals.AppleCareAuthenticate();

                if (Globals.AppleCareSessionDateTime == DateTime.MinValue)
                {
                    PivotalMessageBox.Show("Unable to communicate with Apple Web Service." + Environment.NewLine
                   + "Please contact System Administrator.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                }
                else
                {
                    PivotalMessageBox.Show(message, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                }
                this.FormView.Dirty = false;
            }
            catch (Exception exc)
            {
                Globals.HandleException(exc, true);
            }
        }
    }
}
